Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Reactjs Interview Questions
Description: React is a JavaScript-based UI development library. Facebook and an open-source developer community run it. Although React is a library rather than a language, it is widely used in web development. The library first appeared in May 2013 and is now one of the most commonly used frontend libraries for web development.in this notes i have done 300+ interview questions and answers so that is best for interview from my side

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


its arguments changes
� Back to Top
183
...
Redux Form can be used with raw
HTML5 inputs, but it also works very well with common UI frameworks
like Material UI, React Widgets and React Bootstrap
...

What are the main features of Redux Form?
Some of the main features of Redux Form are:
1
...

2
...

3
...

� Back to Top
185
...


91

For example, you can add redux-thunk and logger passing them as arguments to applyMiddleware():
import { createStore, applyMiddleware } from 'redux'
const createStoreWithMiddleware = applyMiddleware(ReduxThunk, logger)(createStore)
� Back to Top
186
...

How Relay is different from Redux?
Relay is similar to Redux in that they both use a single store
...
Relay caches the data for you and
optimizes data fetching for you, by fetching only changed data and nothing
more
...

What is an action in Redux?
Actions are plain JavaScript objects or payloads of information that send
data from your application to your store
...
Actions must have a type property that indicates
the type of action being performed
...

What is the difference between React Native and React?
React is a JavaScript library, supporting both front end web and being
run on the server, for building user interfaces and web applications
...

� Back to Top
189
...

You can run the app in your mobile using expo app (https://expo
...

� Back to Top
190
...
log, console
...
As of React Native v0
...


93

How to debug your React Native?
Follow the below steps to debug React Native app:
1
...

2
...

3
...

4
...

5
...


React supported libraries & Integration
� Back to Top
192
...
It was originally written to compute derived data from Redux-like
applications state, but it can’t be tied to any architecture or library
...
If the the same
inputs are provided twice in a row, Reselect returns the cached output
...

� Back to Top
193
...

Flow types can express much more fine-grained distinctions than traditional type systems
...

� Back to Top
194
...


94

PropTypes is a basic type checker (runtime checker) which has been
patched onto React
...
If you want more flexible
typechecking for your entire project Flow/TypeScript are appropriate
choices
...

How to use Font Awesome icons in React?
The below steps followed to include Font Awesome in React:
1
...
Import font-awesome in your index
...
min
...
Add Font Awesome classes in className:
render() {
return

}
� Back to Top
196
...
It exists both as a browser extension (for
Chrome and Firefox), and as a standalone app (works with other environments including Safari, IE, and React Native)
...

1
...
Firefox extension
3
...

Why is DevTools not loading in Chrome for local files?
If you opened a local HTML file in your browser (file://
...

95

� Back to Top
198
...
Create a Polymer element:
jsx harmony /> Polymer({
is: 'calender-element',
ready:
function() {
this
...
Create the Polymer component HTML tag by importing it in a
HTML document, e
...
import it in the index
...
/src/polymer-components/calender-element
...
Use that element in the JSX file:
import React from 'react'
class MyComponent extends React
...

What are the advantages of React over Vue
...
js:
1
...

3
...


Gives more flexibility in large apps developing
...

Suitable for mobile apps creating
...


Note: The above list of advantages are purely opinionated and it vary based
on the professional experience
...

� Back to Top

96

200
...

React

Angular

React is a library and has only
the View layer
React handles rendering on
the server side

Angular is a framework and has complete
MVC functionality
AngularJS renders only on the client side
but Angular 2 and above renders on the
server side
Angular follows the template approach for
HTML, which makes code shorter and easy
to understand
Ionic, Angular’s mobile native app is
relatively less stable and slower

React uses JSX that looks like
HTML in JS which can be
confusing
React Native, which is a React
type to build mobile
applications are faster and
more stable
In React, data flows only in
one way and hence debugging
is easy

In Angular, data flows both way i
...
But they are helpful as base parameters
...

Why React tab is not showing up in DevTools?
When the page loads, React DevTools sets a global named __REACT_DEVTOOLS_GLOBAL_HOOK__,
then React communicates with that hook during initialization
...

� Back to Top
202
...

It removes the mapping between styles and components, and lets you write
actual CSS augmented with JavaScript
...

Give an example of Styled Components?
Lets create and <Wrapper> components with specific styles for<br />each<br> ...<br> h1`<br />font-size: 1<br> ...<br> section`<br />padding: 4em;<br />background: papayawhip;<br />`<br />These two variables, Title and Wrapper, are now components that you<br />can render just like any other react component<br> ...<br> <br />What is Relay?<br />Relay is a JavaScript framework for providing a data layer and client-server<br />communication to web applications using the React view layer<br> ...<br> <br />How to use TypeScript in create-react-app application?<br />Starting from react-scripts@2<br> ...<br> 0 or higher, there is a built-in support for<br />typescript<br> ...<br> e, create-react-app now supports typescript natively<br> ...<br> <br />react-scripts-ts is a set of adjustments to take the standard<br />create-react-app project pipeline and bring TypeScript into the mix<br> ...<br> gitignore<br />�� images<br> ...<br> ts<br />�� node_modules/<br />�� public/<br />�� src/<br />� �� <br> ...<br> json<br />�� tsconfig<br> ...<br> prod<br> ...<br> test<br> ...<br> json<br /><br />Miscellaneous<br />� Back to Top<br />206<br> ...<br> Selectors can compute derived data, allowing Redux to store the minimal possible state<br> ...<br> Selectors are efficient<br> ...<br> <br />3<br> ...<br> They can be used as input to other selectors<br> ...<br> <br />Give an example of Reselect usage? Let’s take calculations and<br />different amounts of a shipment order with the simplified usage of Reselect:<br /><br />99<br /><br /> import { createSelector } from 'reselect'<br />const shopItemsSelector = state => state<br> ...<br> items<br />const taxPercentSelector = state => state<br> ...<br> taxPercent<br />const subtotalSelector = createSelector(<br />shopItemsSelector,<br />items => items<br> ...<br> value, 0)<br />)<br />const taxSelector = createSelector(<br />subtotalSelector,<br />taxPercentSelector,<br />(subtotal, taxPercent) => subtotal * (taxPercent / 100)<br />)<br />export const totalSelector = createSelector(<br />subtotalSelector,<br />taxSelector,<br />(subtotal, tax) => ({ total: subtotal + tax })<br />)<br />let exampleState = {<br />shop: {<br />taxPercent: 8,<br />items: [<br />{ name: 'apple', value: 1<br> ...<br> 95 },<br />]<br />}<br />}<br />console<br> ...<br> 15<br />console<br> ...<br> 172<br />console<br> ...<br> 322 }<br />� Back to Top<br />209<br> ...<br> createClass():<br />someComponent= React<br> ...<br> <br />}<br />}<br />})<br />But you can write statics inside ES6+ classes as below,<br />class Component extends React<br> ...<br> <br />}<br />static someMethod() {<br />// <br> ...<br> Component {<br /><br> ...<br> propTypes = {<br> ...<br> someMethod = function(){<br> ...<br> <br />Can Redux only be used with React?<br />Redux can be used as a data store for any UI layer<br> ...<br> Redux simply provides a<br />subscription mechanism which can be used by any other code<br> ...<br> <br />Do you need to have a particular build tool to use Redux?<br />Redux is originally written in ES6 and transpiled for production into ES5<br />with Webpack and Babel<br> ...<br> Redux also offers a UMD build that can be used<br />directly without any build process at all<br> ...<br> <br /><br />101<br /><br /> How Redux Form initialValues get updated from state?<br />You need to add enableReinitialize : true setting<br> ...<br> <br />� Back to Top<br />213<br> ...<br> <br />For example, the height property can be defined with either string or<br />number type as below:<br />Component<br> ...<br> oneOfType([<br />PropTypes<br> ...<br> number<br />])<br />}<br />� Back to Top<br />214<br> ...<br> <br />This feature is available with react-scripts@2<br> ...<br> 0 and higher<br> ...<br> /logo<br> ...<br> <br />� Back to Top<br />215<br> ...<br> <br />This is because a new instance of the function is created with each render,<br />so React needs to clear the old ref and set up the new one<br> ...<br> log("Input Value is: ", this<br> ...<br> value)<br />}<br /><br />render () {<br />return (<br /><form onSubmit={this<br> ...<br> input = input} /> // Access DOM input in handle submit<br /><button type='submit'>Submit</button><br /></form><br />)<br />}<br />}<br />But our expectation is for the ref callback to get called once, when the<br />component mounts<br> ...<br> log("Input Value is: ", this<br> ...<br> value)<br />}<br />setSearchInput = (input) => {<br />this<br> ...<br> handleSubmit}><br /><input<br />type='text'<br />ref={this<br> ...<br> 3,<br />� Back to Top<br />216<br> ...<br> It means that you decorate your<br />component by wrapping it into a Higher-Order component<br> ...<br> It does not actually enable hijacking, but by<br />using HOC you make your component behave differently<br> ...<br> <br />What are HOC factory implementations?<br />There are two main ways of implementing HOCs in React<br> ...<br> Props Proxy (PP) and<br />2<br> ...<br> <br />But they follow different approaches for manipulating the WrappedComponent<br> ...<br> We also pass through the props<br />that the HOC receives, hence the name Props Proxy<br> ...<br> Component {<br />render() {<br />return <WrappedComponent {<br> ...<br> props}/><br />}<br />}<br />}<br />Inheritance Inversion<br />In this approach, the returned HOC class (Enhancer) extends the<br />WrappedComponent<br> ...<br> In this way the relationship between them<br />seems inverse<br> ...<br> render()<br />}<br />}<br />}<br />� Back to Top<br />218<br> ...<br> render(<User age={30} department={"IT"} />, document<br> ...<br> <br />Do I need to keep all my state into Redux? Should I ever use<br />react internal state?<br />It is up to the developer’s decision, i<br> ...<br> , it is developer’s job to determine<br />what kinds of state make up your application, and where each piece of<br />state should live<br> ...<br> Others prefer to keep non-critical or UI state,<br />such as “is this dropdown currently open”, inside a component’s internal<br />state<br> ...<br> Do other parts of the application care about this data?<br />2<br> ...<br> Is the same data being used to drive multiple components?<br />4<br> ...<br> Do you want to cache the data (i<br> ...<br> <br />What is the purpose of registerServiceWorker in React?<br />React creates a service worker for you without any configuration by default<br> ...<br> <br />It’s all about adding offline capabilities to your site<br> ...<br> /App';<br />registerServiceWorker from '<br> ...<br> render(<App />, document<br> ...<br> <br />What is React memo function?<br />Class components can be restricted from re-rendering when their input<br />props are the same using PureComponent or shouldComponentUpdate<br> ...<br> memo<br> ...<br> memo(function MyComponent(props) {<br />/* only rerenders if props change */<br />});<br />� Back to Top<br />222<br> ...<br> lazy function lets you render a dynamic import as a regular component<br> ...<br> This must return<br />a Promise which resolves to a module with a default export containing a<br />React component<br> ...<br> lazy(() => import('<br> ...<br> lazy and Suspense is not yet available for server-side rendering<br> ...<br> <br />� Back to Top<br />223<br> ...<br> If the values are the same<br />then you need to return null to stop re-rendering otherwise return the<br />latest state value<br> ...<br> setState(state<br />if (state<br> ...<br> address;<br />=> {<br />=== latestAddress) {<br /><br />latestAddress };<br /><br />� Back to Top<br />224<br> ...<br> You are able to return multiple<br />sibling elements without a wrapping element by returning an array<br> ...<br> <br />const JSDevs = () => {<br />return (<br /><ul><br /><li>Brad</li><br /><li>Brodge</li><br /><ReactJSDevs/><br /><li>Brandon</li><br /></ul><br />);<br />}<br />Strings and Numbers: You can also return string and number type<br />from the render method<br> ...<br> <br />How to use class field declarations syntax in React classes?<br />React Class Components can be made much more concise using the class<br />field declarations<br> ...<br> <br />Let’s take a counter example to demonstrate class field declarations for<br />state without using constructor and methods without binding,<br />class Counter extends Component {<br />state = { value: 0 };<br />handleIncrement = () => {<br />this<br> ...<br> value + 1<br />}));<br />108<br /><br /> };<br />handleDecrement = () => {<br />this<br> ...<br> value - 1<br />}));<br />};<br />render() {<br />return (<br /><div><br />{this<br> ...<br> value}<br /><button onClick={this<br> ...<br> handleDecrement}>-</button><br /></div><br />)<br />}<br />}<br />� Back to Top<br />226<br> ...<br> 8) that lets you use state and other React<br />features without writing a class<br> ...<br> <br />What rules need to be followed for hooks?<br />You need to follow two rules in order to use hooks,<br />1<br> ...<br> i<br> ...<br> <br />This will ensure that Hooks are called in the same order each time<br />a component renders and it preserves the state of Hooks between<br />multiple useState and useEffect calls<br> ...<br> Call Hooks from React Functions only<br> ...<br> e, You shouldn’t call Hooks<br />from regular JavaScript functions<br> ...<br> <br />How to ensure hooks followed the rules in your project?<br />React team released an ESLint plugin called eslint-plugin-reacthooks that enforces these two rules<br> ...<br> <br />"react-hooks"<br />],<br />"rules": {<br />// <br> ...<br> <br />� Back to Top<br />229<br> ...<br> <br />What are the benefits of React Router V4?<br />Below are the main benefits of React Router V4 module,<br />1<br> ...<br> <br />A router can be visualized as a single component(<BrowserRouter>) which wraps specific child router components(<Route>)<br> ...<br> You don’t need to manually set history<br> ...<br> <br />3<br> ...<br> <br />Can you describe about componentDidCatch lifecycle method<br />signature?<br />The componentDidCatch lifecycle method is invoked after an error has<br />been thrown by a descendant component<br> ...<br> error: - The error object which was thrown<br />2<br> ...<br> <br />The method structure would be as follows<br />componentDidCatch(error, info)<br />� Back to Top<br />232<br> ...<br> Inside Event handlers<br />2<br> ...<br> During Server side rendering<br />4<br> ...<br> <br />111<br /><br /> Why do you not need error boundaries for event handlers?<br />Error boundaries do not catch errors inside event handlers<br> ...<br> Unlike the render method and lifecycle methods, the event handlers<br />don’t happen during rendering<br> ...<br> <br />If you need to catch an error inside an event handler, use the regular<br />JavaScript try / catch statement:<br />class MyComponent extends React<br> ...<br> state = { error: null };<br />this<br> ...<br> handleClick<br> ...<br> setState({ error });<br />}<br />}<br />render() {<br />if (this<br> ...<br> error) {<br />return <h1>Caught an error<br> ...<br> handleClick}>Click Me</button><br />}<br />}<br />Note that the above example is demonstrating regular JavaScript behavior<br />and doesn’t use error boundaries<br> ...<br> <br />What is the difference between try catch block and error boundaries?<br />Try catch block works with imperative code whereas error boundaries are<br />meant for declarative code to render on the screen<br> ...<br> <br />}<br />Whereas error boundaries wrap declarative code as below,<br /><ErrorBoundary><br /><MyComponent /><br /></ErrorBoundary><br />So if an error occurs in a componentDidUpdate method caused by a<br />setState somewhere deep in the tree, it will still correctly propagate to<br />the closest error boundary<br> ...<br> <br />What is the behavior of uncaught errors in react 16?<br />In React 16, errors that were not caught by any error boundary will result<br />in unmounting of the whole React component tree<br> ...<br> For example, it is worse for a payments app to<br />display a wrong amount than to render nothing<br> ...<br> <br />What is the proper placement for error boundaries?<br />The granularity of error boundaries usage is up to the developer based on<br />project needs<br> ...<br> You can wrap top-level route components to display a generic error<br />message for the entire application<br> ...<br> You can also wrap individual components in an error boundary to<br />protect them from crashing the rest of the application<br> ...<br> <br />What is the benefit of component stack trace from error boundary?<br />Apart from error messages and javascript stack, React16 will display the<br />component stack trace with file names and line numbers using error boundary concept<br> ...<br> <br />What is the required method to be defined for a class component?<br />The render() method is the only required method in a class component<br> ...<br> e, All methods other than render method are optional for a class component<br> ...<br> <br />What are the possible return types of render method?<br />Below are the list of following types used and return from render method,<br />1<br> ...<br> It includes html elements such as <div/> and user defined<br />elements<br> ...<br> Arrays and fragments: Return multiple elements to render as<br />Arrays and Fragments to wrap multiple elements<br />3<br> ...<br> <br />4<br> ...<br> Booleans or null: Doesn’t render anything but these types are used<br />to conditionally render content<br> ...<br> <br />What is the main purpose of constructor?<br />The constructor is mainly used for two purposes,<br />1<br> ...<br> state<br /><br />114<br /><br /> 2<br> ...<br> setState() here!<br />this<br> ...<br> handleClick = this<br> ...<br> bind(this);<br />}<br />� Back to Top<br />241<br> ...<br> i<br> ...<br> <br />� Back to Top<br />242<br> ...<br> This is used for undefined props, but not<br />for null props<br> ...<br> Component {<br />// <br> ...<br> defaultProps = {<br />color: 'red'<br />};<br />If props<br> ...<br> <br />i<br> ...<br> color will be set to red<br />}<br />Note: If you provide null value then it remains null value<br> ...<br> <br /><br />115<br /><br /> Why should not call setState in componentWillUnmount?<br />You should not call setState() in componentWillUnmount() because<br />once a component instance is unmounted, it will never be mounted again<br> ...<br> <br />What is the purpose of getDerivedStateFromError?<br />This lifecycle method is invoked after an error has been thrown by a descendant component<br> ...<br> <br />The signature of the lifecycle method is as follows,<br />static getDerivedStateFromError(error)<br />Let us take error boundary use case with the above lifecycle method for<br />demonstration purpose,<br />class ErrorBoundary extends React<br> ...<br> state = { hasError: false };<br />}<br />static getDerivedStateFromError(error) {<br />// Update state so the next render will show the fallback UI<br> ...<br> state<br> ...<br> </h1>;<br />}<br />return this<br> ...<br> children;<br />}<br />}<br />� Back to Top<br />245<br> ...<br> The below methods<br />are called in the following order when a component is being re-rendered<br> ...<br> <br />2<br> ...<br> <br />4<br> ...<br> <br /><br />static getDerivedStateFromProps()<br />shouldComponentUpdate()<br />render()<br />getSnapshotBeforeUpdate()<br />componentDidUpdate()<br /><br />� Back to Top<br />246<br> ...<br> <br />1<br> ...<br> componentDidCatch()<br />� Back to Top<br />247<br> ...<br> Usually, you don’t<br />need to set it explicitly because it’s inferred from the name of the function<br />or��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������value = this<br> ...<br> */<br />}<br />render() {<br />let value = this<br> ...<br> contextType = MyContext;<br />2<br> ...<br> <br /><br />133<br /><br /> class MyClass extends React<br> ...<br> context;<br />/* render something based on the value */<br />}<br />}<br />� Back to Top<br />280<br> ...<br> <br />It requires a function as a child which receives current context value as<br />argument and returns a react node<br> ...<br> <br />Lets take a simple example,<br /><MyContext<br> ...<br> Consumer><br />� Back to Top<br />281<br> ...<br> <br />For example, the code below will re-render all consumers every time the<br />Provider re-renders because a new object is always created for value<br> ...<br> Component {<br />render() {<br />return (<br /><Provider value={{something: 'something'}}><br /><Toolbar /><br /></Provider><br />);<br />}<br />}<br />This can be solved by lifting up the value to parent state,<br /><br />134<br /><br /> class App extends React<br> ...<br> state = {<br />value: {something: 'something'},<br />};<br />}<br />render() {<br />return (<br /><Provider value={this<br> ...<br> value}><br /><Toolbar /><br /></Provider><br />);<br />}<br />}<br />� Back to Top<br />282<br> ...<br> It is handled<br />differently by React just like key<br> ...<br> In this case, you can use Forward Ref API<br> ...<br> forwardRef API<br> ...<br> Component {<br />componentDidUpdate(prevProps) {<br />console<br> ...<br> log('new props:', this<br> ...<br> rest} = this<br> ...<br> rest} />;<br />}<br />}<br />return React<br> ...<br> props} forwardedRef={ref} />;<br />});<br />}<br />Let’s use this HOC to log all props that get passed to our “fancy button”<br />component,<br />class FancyButton extends React<br> ...<br> <br />}<br />// <br> ...<br> In this case,<br />you can set focus to button element<br> ...<br> /FancyButton';<br />const ref = React<br> ...<br> current<br> ...<br> <br />Is ref argument available for all functions or class components?<br />Regular function or class components don’t receive the ref argument, and<br />ref is not available in props either<br> ...<br> forwardRef call<br> ...<br> <br />Why do you need additional care for component libraries while<br />using forward refs?<br />When you start using forwardRef in a component library, you should treat<br />it as a breaking change and release a new major version of your library<br> ...<br> These changes can<br />break apps and other libraries that depend on the old behavior<br> ...<br> <br />How to create react class components without ES6?<br />If you don’t use ES6 then you may need to use the create-react-class<br />module instead<br> ...<br> Whereas for initial state, you have to<br />provide a separate getInitialState method that returns the initial state<br> ...<br> props<br> ...<br> log(this<br> ...<br> message);<br />},<br />render: function() {<br />return <h1>Hello, {this<br> ...<br> name}</h1>;<br />}<br />});<br />Note: If you use createReactClass then auto binding is available for all<br />methods<br> ...<br> e, You don’t need to use <br> ...<br> <br />� Back to Top<br />286<br> ...<br> <br />Actually it is convenient when you don’t want to set up compilation in your build<br />environment<br> ...<br> createElement(component, props, <br> ...<br> <br />For example, let us take a greeting example with JSX,<br />class Greeting extends React<br> ...<br> props<br> ...<br> render(<br /><Greeting message="World" />,<br />document<br> ...<br> Component {<br />render() {<br />return React<br> ...<br> props<br> ...<br> render(<br />React<br> ...<br> getElementById('root')<br />);<br />� Back to Top<br />287<br> ...<br> The diffing algorithms is generating<br />the minimum number of operations to transform one tree into another<br> ...<br> <br />In this case, displaying 1000 elements would require in the order of one<br />billion comparisons<br> ...<br> Instead, React implements<br />a heuristic O(n) algorithm based on two assumptions:<br />1<br> ...<br> <br />2<br> ...<br> <br />� Back to Top<br />288<br> ...<br> The<br />behavior is different depending on the types of the root elements<br> ...<br> Elements Of Different Types: Whenever the root elements have<br />different types, React will tear down the old tree and build the new<br />tree from scratch<br> ...<br> <br />2<br> ...<br> Lets take an example with same DOM elements except<br />className attribute,<br /><div className="show" title="ReactJS" /><br /><div className="hide" title="ReactJS" /><br />3<br> ...<br> React updates the props of the underlying component<br />instance to match the new element, and calls componentWillReceiveProps() and componentWillUpdate() on the underlying instance<br> ...<br> <br />4<br> ...<br> For example, when adding an element at the end of the children, converting<br />between these two trees works well<br> ...<br> Handling keys: React supports a key attribute<br> ...<br> For example, adding a key can<br />make the tree conversion efficient,<br /><ul><br /><li key="2015">Duke</li><br /><br />139<br /><br /> <li key="2016">Villanova</li><br /></ul><br /><ul><br /><li key="2014">Connecticut</li><br /><li key="2015">Duke</li><br /><li key="2016">Villanova</li><br /></ul><br />� Back to Top<br />289<br> ...<br> Managing focus, text selection, or media playback<br> ...<br> Triggering imperative animations<br> ...<br> Integrating with third-party DOM libraries<br> ...<br> <br />Must prop be named as render for render props?<br />Even though the pattern named render props, you don’t have to use a<br />prop named render to use this pattern<br> ...<br> e, Any prop that is a function<br />that a component uses to know what to render is technically a “render<br />prop”<br> ...<br> x}, {mouse<br> ...<br> Instead, you can keep it directly inside element,<br /><Mouse><br />{mouse => (<br /><p>The mouse position is {mouse<br> ...<br> y}</p><br />)}<br /></Mouse><br />While using this above technique(without any name), explicitly state that<br />children should be a function in your propTypes<br> ...<br> propTypes = {<br />children: PropTypes<br> ...<br> isRequired<br />};<br /><br />140<br /><br /> � Back to Top<br />291<br> ...<br> Because the shallow prop comparison will always<br />return false for new props, and each render in this case will generate a<br />new value for the render prop<br> ...<br> <br />� Back to Top<br />292<br> ...<br> For example, if you would prefer to have<br />a withMouse HOC instead of a component, you could easily create one<br />using a regular with a render prop<br> ...<br> Component {<br />render() {<br />return (<br /><Mouse render={mouse => (<br /><Component {<br> ...<br> props} mouse={mouse} /><br />)}/><br />);<br />}<br />}<br />}<br />This way render props gives the flexibility of using either pattern<br> ...<br> <br />What is windowing technique?<br />Windowing is a technique that only renders a small subset of your rows at<br />any given time, and can dramatically reduce the time it takes to re-render<br />the components as well as the number of DOM nodes created<br> ...<br> <br />Both react-window and react-virtualized are popular windowing libraries<br /><br />141<br /><br /> which provides several reusable components for displaying lists, grids, and<br />tabular data<br> ...<br> <br />How do you print falsy values in JSX?<br />The falsy values such as false, null, undefined, and true are valid children<br />but they don’t render anything<br> ...<br> Let’s take an example on how to convert to<br />a string,<br /><div><br />My JavaScript variable is {String(myVariable)}<br> ...<br> <br />What is the typical use case of portals?<br />React portals are very useful when a parent component has overflow: hidden or has properties that affect the stacking context (e<br> ...<br> z-index, position, opacity) and you need to visually “break out” of its container<br> ...<br> <br />� Back to Top<br />296<br> ...<br> With an uncontrolled component, you might want React to<br />specify the initial value, but leave subsequent updates uncontrolled<br> ...<br> <br />render() {<br />return (<br /><form onSubmit={this<br> ...<br> input} /><br /></label><br /><input type="submit" value="Submit" /><br /></form><br />);<br />}<br />The same applies for select and textArea inputs<br> ...<br> <br />� Back to Top<br />297<br> ...<br> It mainly uses Redux and redux-saga for state management and asynchronous side-effects,<br />react-router for routing purpose, styled-components for styling react<br />components, axios for invoking REST api, and other supported stack<br />such as webpack, reselect, ESNext, Babel<br> ...<br> com/react-boilerplate/react-boilerplate and start working<br />on any new react project<br> ...<br> <br />What is the difference between Real DOM and Virtual DOM?<br />Below are the main differences between Real DOM and Virtual DOM,<br />Real DOM<br /><br />Virtual DOM<br /><br />Updates are slow<br />DOM manipulation is very expensive<br> ...<br> <br />It causes too much of memory wastage<br />Creates a new DOM if element updates<br /><br />Updates are fast<br />DOM manipulation is very easy<br />You Can’t directly update HTML<br />There is no memory wastage<br />It updates the JSX if element update<br /><br />� Back to Top<br />299<br> ...<br> Using the Bootstrap CDN: This is the easiest way to add bootstrap<br> ...<br> <br />2<br> ...<br> React Bootstrap Package: In this case, you can add Bootstrap to our<br />React app is by using a package that has rebuilt Bootstrap components to work particularly as React components<br> ...<br> react-bootstrap<br />2<br> ...<br> <br />Can you list down top websites or applications using react as<br />front end framework?<br />Below are the top 10 websites using React as their front-end framework,<br />1<br> ...<br> <br />3<br> ...<br> <br />5<br> ...<br> <br />7<br> ...<br> <br />9<br> ...<br> <br /><br />Facebook<br />Uber<br />Instagram<br />WhatsApp<br />Khan Academy<br />Airbnb<br />Dropbox<br />Flipboard<br />Netflix<br />PayPal<br /><br />� Back to Top<br />301<br> ...<br> css file as usual and refer to them using className<br> ...<br> But If you want<br />to try a different approach(CSS-In-JS) then styled-components library is<br />a good option<br> ...<br> <br />Do I need to rewrite all my class components with hooks?<br />No<br> ...<br> Because there are no plans to remove<br />classes in ReactJS<br> ...<br> <br />How to fetch data with React Hooks?<br />The effect hook called useEffect is used to fetch the data with axios from<br />the API and to set the data in the local state of the component with the<br />state hook’s update function<br> ...<br> algolia<br> ...<br> data);<br />})()<br />}, []);<br />return (<br /><ul><br />{data<br> ...<br> map(item => (<br /><li key={item<br> ...<br> url}>{item<br> ...<br> i<br> ...<br> <br />� Back to Top<br />304<br> ...<br> Currently there are no Hook equivalents to the uncommon<br />getSnapshotBeforeUpdate and componentDidCatch lifecycles yet<br> ...<br> <br />What is the stable release for hooks support?<br />React includes a stable implementation of React Hooks in 16<br> ...<br> <br />2<br> ...<br> <br />4<br> ...<br> <br />Why do we use array destructuring (square brackets notation)<br />in useState?<br />When we declare a state variable with useState, it returns a pair — an<br />array with two items<br> ...<br> Using [0] and [1] to access them is<br />a bit confusing because they have a specific meaning<br> ...<br> <br />For example, the array index access would look as follows:<br />var userStateVariable = useState('userProfile'); // Returns an array pair<br />var user = userStateVariable[0]; // Access first item<br />var setUser = userStateVariable[1]; // Access second item<br />Whereas with array destructuring the variables can be accessed as follows:<br />const [user, setUser] = useState('userProfile');<br />� Back to Top<br /><br />146<br /><br /> 307<br> ...<br> Below are some of<br />them,<br />1<br> ...<br> Community experiments with render prop APIs such as Reactions<br />Component<br />3<br> ...<br> <br />4<br> ...<br> <br />5<br> ...<br> <br />� Back to Top<br />308<br> ...<br> You will need to use a ref to interact with the DOM node directly<br />if you want to access imperative API of a web component<br> ...<br> <br />� Back to Top<br />309<br> ...<br> Getting values in and out of form state<br />2<br> ...<br> Handling form submission<br />� Back to Top<br />310<br> ...<br> <br />� Back to Top<br /><br />147<br /><br /> 311<br> ...<br> You need a transpiler to convert<br />your JSX to regular Javascript that browsers can understand<br> ...<br> <br />� Back to Top<br />312<br> ...<br> <br />� Back to Top<br />313<br> ...<br> The<br />react-scripts start command sets up the development environment<br />and starts a server, as well as hot module reloading<br> ...<br> <br />What are the features of create react app?<br />Below are the list of some of the features provided by create react app<br> ...<br> React, JSX, ES6, Typescript and Flow syntax support<br> ...<br> Autoprefixed CSS<br />3<br> ...<br> A live development server<br />5<br> ...<br> A build script to bundle JS, CSS, and images for production, with<br />hashes and sourcemaps<br />7<br> ...<br> <br />� Back to Top<br /><br />148<br /><br /> 315<br> ...<br> It also helps search engines to crawl your pages easily<br />for SEO purposes<br> ...<br> <br />� Back to Top<br />316<br> ...<br> For reactJs application, you need to install below packages, bash<br />npm install mobx<br />--save<br />npm install mobx-react --save<br />� Back to Top<br />317<br> ...<br> <br /><br />149<br /><br /> Should I learn ES6 before learning ReactJS?<br />No, you don’t have to learn es2015/es6 to learn react<br> ...<br> Let’s see some<br />of the frequently used ES6 features,<br />1<br> ...<br> props<br> ...<br> props<br> ...<br> props “‘<br />2<br> ...<br> props} /> “‘<br />3<br> ...<br> map(function (user) {<br />return<br /><li>{user<br> ...<br> map(user => <li>{user<br> ...<br> <br />What is Concurrent Rendering?<br />The Concurrent rendering makes React apps to be more responsive by<br />rendering component trees without blocking the main UI thread<br> ...<br> <br />i<br> ...<br> You can enable this in two ways,<br />// 1<br> ...<br> unstable_ConcurrentMode><br /><Something /><br /></React<br> ...<br> Whole app using createRoot<br />ReactDOM<br> ...<br> render(<App />);<br />� Back to Top<br />320<br> ...<br> Previously concurrent Mode being referred to<br />as “Async Mode” by React team<br> ...<br> So it avoids<br />the confusion from other approaches to Async Rendering<br> ...<br> <br />Can I use javascript urls in react16<br> ...<br> Because URLs starting with javascript: are dangerous by including<br />unsanitized output in a tag like <a href> and create a security hole<br> ...<br> website}>More details</a><br />Remember that the future versions will throw an error for javascript URLs<br> ...<br> <br />What is the purpose of eslint plugin for hooks?<br />The ESLint plugin enforces rules of Hooks to avoid bugs<br> ...<br> In particular, the rule enforces that,<br />1<br> ...<br> <br />2<br> ...<br> <br />� Back to Top<br />323<br> ...<br> When you tap<br />it, it turns blue if it was previously grey, and grey if it was previously blue<br> ...<br> likes() ) {<br />if( hasBlue() ) {<br />removeBlue();<br />addGrey();<br />} else {<br />removeGrey();<br />addBlue();<br />}<br />}<br />Basically, you have to check what is currently on the screen and handle<br />all the changes necessary to redraw it with the current state, including undoing the changes from the previous state<br> ...<br> <br />In contrast, the declarative approach would be:<br />if( this<br> ...<br> liked ) {<br />return <blueLike />;<br />} else {<br />return <greyLike />;<br />}<br />Because the declarative approach separates concerns, this part of it only<br />needs to handle how the UI should look in a sepecific state, and is therefore<br />much simpler to understand<br> ...<br> <br />What are the benefits of using typescript with reactjs?<br />Below are some of the benefits of using typescript with Reactjs,<br />1<br> ...<br> <br />3<br> ...<br> <br /><br />It is possible to use latest JavaScript features<br />Use of interfaces for complex type definitions<br />IDEs such as VS Code was made for TypeScript<br />Avoid bugs with the ease of readability and Validation<br /><br />� Back to Top<br />325<br> ...<br> js<br> ...<br> <br /><br />152<br /><br /> App<br> ...<br> /actions/auth';<br />store<br> ...<br> js, wrap the<br />AuthState in index<br> ...<br> js can access the auth context<br> ...<br> <br />index<br> ...<br> /App';<br />AuthState from '<br> ...<br> render(<br /><React<br> ...<br> StrictMode>,<br />document<br> ...<br> js<br />const authContext = useContext(AuthContext);<br />const { loadUser } = authContext;<br />useEffect(() => {<br />loadUser();<br />},[])<br />loadUser<br />const loadUser = async () => {<br />const token = sessionStorage<br> ...<br> data<br> ...<br> error(err);<br />}<br />}<br />� Back to Top<br />326<br> ...<br> It is possible to use JSX without importing React packages<br />2<br> ...<br> The future improvements provides the flexibility to reduce the number of concepts to learn React<br> ...<br> <br />How does new JSX transform different from old transform?<br />The new JSX transform doesn’t require React to be in scope<br> ...<br> e, You<br />don’t need to import React package for simple scenarios<br> ...<br> createElement('h1', null, 'Good morning!!');<br />}<br />New Transform:<br />The new JSX transform doesn’t require any React imports<br />function App() {<br />return <h1>Good morning!!</h1>;<br />}<br />Under the hood JSX transform compiles to below code<br />import {jsx as _jsx} from 'react/jsx-runtime';<br />function App() {<br />return _jsx('h1', { children: 'Good morning!!' });<br />}<br />Note: You still need to import React to use Hooks<br> ...<br> <br />How do you get redux scaffolding using create-react-app?<br />Redux team has provided official redux+js or redux+typescript templates<br />for create-react-app project<br> ...<br> <br />2<br> ...<br> <br />4<br> ...<br> Javascript template:<br />npx create-react-app my-app --template redux<br />2<br> ...<br> <br /><br />155<br /><br /> What are React Server components?<br />React Server Component is a way to write React component that gets rendered in the server-side with the purpose of improving React app performance<br> ...<br> <br />Note: React Server Components is still under development and not recommended for production yet<br> ...<br> <br />What is prop drilling?<br />Prop Drilling is the process by which you pass data from one component of<br />the React Component tree to another by going through other components<br />that do not need the data but only help in passing it around<br> ...<br> <br />What is state mutation and how to prevent it?<br />State mutation happens when you try to update the state of a component without actually using setState function<br> ...<br> This is the main<br />reason why it is advised to return new instances of state variables from<br />the reducers by using Object<br> ...<br> <br />This can cause unknown issues in the UI as the value of the state variable<br />got updated without telling React to check what all components were<br />being affected from this update and it can cause UI bugs<br> ...<br> component { constructor(props) {<br />super(props); this<br> ...<br> state; loading = (() =><br />true)(); // Trying to perform an operation and directly saving in a state<br />variable }<br />“‘<br />How to prevent it: Make sure your state variables are immutable by<br />either enforcing immutability by using plugins like Immutable<br> ...<br> <br />� Back to Top<br />332<br> ...<br> useState causes components to re-render after state updates whereas<br />useRef doesn’t cause a component to re-render when the value or<br />state changes<br> ...<br> current) property<br> ...<br> useState allows us to update the state inside components<br> ...<br> <br />� Back to Top<br /><br />Disclaimer<br />The questions provided in this repository are the summary of frequently asked<br />questions across numerous companies<br> ...<br> The primary purpose is for you to get a sense of<br />what some companies might ask — do not get discouraged if you don’t know<br />the answer to all of them — that is ok!<br />Good luck with your interview �<br /><br />157<br /><br /> <hr /><div class="preview_top"><b>Title:</b> Reactjs Interview Questions<br/><b>Description:</b> React is a JavaScript-based UI development library. Facebook and an open-source developer community run it. Although React is a library rather than a language, it is widely used in web development. The library first appeared in May 2013 and is now one of the most commonly used frontend libraries for web development.in this notes i have done 300+ interview questions and answers so that is best for interview from my side<br/><div class="noteinfo"><a class="buybasket" href="/buy/273454">Buy These Notes</a><a class="action preview" href="preview/273454">Preview</a></div></div> </div> </div> </div> <div class="container"> <div id="footer"> <ul class="info"> <li><a href="become-a-notesale-ambassador">Become a Notesale Ambassador</a></li> </ul> <ul class="anc"> <li><a href="terms-and-conditions">Ts and Cs</a></li> <li class="last"><a href="contact-us">Contact Us</a></li> </ul> </div> </div> <script type="text/javascript" src="/path.js"></script> <script type="text/javascript" src="/notesale.js"></script> </body> </html>